//
//  BaseAllViewController.m
//  EducationAdminClient
//
//  Created by kwsdzjx on 15/11/25.
//  Copyright © 2015年 周佳兴. All rights reserved.
//

#import "BaseAllViewController.h"

@implementation BaseAllViewController
-(void)viewDidLoad{
    [super viewDidLoad];
//    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
//    if([userDefault valueForKey:PROGRAMA])_programaUrl = [NSString stringWithFormat:@"http://%@:%@/edus_auto/", [userDefault valueForKey:PROGRAMA], [userDefault valueForKey:PORT]];
//    
//    NSString *str = [userDefault valueForKey:PROGRAMA];
//    if (str.length<=0) {
        self.programaUrl = getBase();
    //}
    self.view.backgroundColor =  [UIColor colorWithHex:0xf4f4f4];;
//#ifdef Main
    //这里添加版本UI判断
    if([getUIStyle() isEqualToString:STYLE0]){
    NSLog(@"主项目程序");
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"nav3"] forBarMetrics:UIBarMetricsDefault];
    }else{
//#elif Student
    
    NSLog(@"学员端程序");
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"bgbgbg"] forBarMetrics:UIBarMetricsDefault];
    }//原来的navigation_bg
    //    [self dataRequest];
    
    //    return YES;
    
//#elif Teacher
//    //    rootview
//    NSLog(@"老师端程序");
//#else
//    
//    NSLog(@"都不是");
//#endif
//    [self.navigationController.navigationBar setBackgroundColor:[UIColor colorWithRed:56/255.0 green:64/255.0 blue:77/255.0 alpha:1]];
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(netNotifation:) name:@"netState" object:nil];
}


//-(void)setProgramaUrl:(NSString *)programaUrl{
//    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
//    if([userDefault valueForKey:PROGRAMA])_programaUrl = [NSString stringWithFormat:@"%@", [userDefault valueForKey:PROGRAMA]];
//
//}
-(void)netNotifation:(NSNotification *)noti{

}
-(void)viewDidAppear:(BOOL)animated{
    self.selecCell = NO;
    [super viewDidAppear:animated];
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)])
    {
        self.navigationController.interactivePopGestureRecognizer.enabled = YES;
        self.navigationController.interactivePopGestureRecognizer.delegate = self;
    }
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.titleLabelSet = nil;
}
-(void)setTitleLabelText:(NSString *)titleLabel1{
    self.titleLabelSet = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 50, 30)];
    //    label.backgroundColor = [UIColor redColor];
    _titleLabelSet.textColor = [UIColor whiteColor];
    _titleLabelSet.font = [UIFont systemFontOfSize:36/2];
    _titleLabelSet.text = titleLabel1;
    self.navigationItem.titleView = _titleLabelSet;
    
}

-(void)showLabelWithText:(NSString *)text{
    if(self.requeatResultLabel!=nil)return;
    self.requeatResultLabel = [[UILabel alloc]init];
    self.requeatResultLabel.backgroundColor = [UIColor colorWithRed:30/255.0 green:25/255.0 blue:77/255.0 alpha:0.4];
    self.requeatResultLabel.textColor = [UIColor whiteColor];
    self.requeatResultLabel.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:self.requeatResultLabel];
    if(CURRENTVERSION<9.0){
        self.requeatResultLabel.frame = CGRectMake(0, -25, self.view.bounds.size.width, 25);
        CGRect frame = self.requeatResultLabel.frame;
        self.requeatResultLabel.text = [NSString stringWithFormat:@"%@", text];
        self.requeatResultLabel.font = [UIFont systemFontOfSize:14];
        [self.view bringSubviewToFront:self.requeatResultLabel];
        [UIView animateWithDuration:1 animations:^{
            self.requeatResultLabel.frame = CGRectMake(0, 0, self.view.bounds.size.width, 25);
            
        } completion:^(BOOL finished) {
            [UIView animateWithDuration:1 animations:^{
                self.requeatResultLabel.frame = frame;
            } completion:^(BOOL finished) {
                [self.requeatResultLabel removeFromSuperview];
                self.requeatResultLabel = nil;
            }];
        }];
    }else{
        self.requeatResultLabel.frame = CGRectMake(0, 0, self.view.bounds.size.width, 0);
        CGRect frame = self.requeatResultLabel.frame;
        self.requeatResultLabel.text = [NSString stringWithFormat:@"%@", text];
        self.requeatResultLabel.font = [UIFont systemFontOfSize:14];
        [self.view bringSubviewToFront:self.requeatResultLabel];
        [UIView animateWithDuration:1 animations:^{
            self.requeatResultLabel.frame = CGRectMake(0, 0, self.view.bounds.size.width, 25);
            
        } completion:^(BOOL finished) {
            [UIView animateWithDuration:1 animations:^{
                self.requeatResultLabel.frame = frame;
            } completion:^(BOOL finished) {
                [self.requeatResultLabel removeFromSuperview];
                self.requeatResultLabel = nil;
            }];
        }];

    }
}

-(void)createLeftNavBar{
    UIButton *leftNavBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftNavBtn.frame = CGRectMake(0, 0, 11, 37/2);
    [leftNavBtn setBackgroundImage:[UIImage imageNamed:@"形状1-19-拷贝-4"] forState:UIControlStateNormal];
    [leftNavBtn addTarget:self action:@selector(LeftClick:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithCustomView:leftNavBtn];
    self.navigationItem.leftBarButtonItem = item;
    
}

-(void)LeftClick:(UIButton *)btn{
    [self.navigationController popViewControllerAnimated:YES];
}

#warning this is must rewrite that subClasses use
#pragma UITableViewDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 0;
}

//-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//    return nil;
//}

#warning this is must rewrite that subClasses use
#pragma mark - UICollectionViewDataSource
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 0;
}

- (void)sessionIsOverTime:(NSString *)dataStr{
    NSRange range = [dataStr rangeOfString:@"登录超时"];
    
    if (range.location != NSNotFound) {
//        [self showLabelWithText:@"登录超时，请重新登录"];
        [[UIApplication sharedApplication]setNetworkActivityIndicatorVisible:NO];
//        NSNotificationCenter *noti = [NSNotificationCenter defaultCenter];
        saveLoginState(NLOGSTATE);
        //#ifdef Main
        
        //#ifdef Main
        
        [[NSNotificationCenter defaultCenter]postNotificationName:@"relogin" object:@"relogin"];
//        if([getUIStyle() isEqualToString:STYLE0]){
//            NSLog(@"主项目程序");
//            [noti postNotificationName:@"login" object:@"exit"];
//            NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
//            [ud removeObjectForKey:@"roleNames"];//将登录人的角色信息清除掉。
//            [ud removeObjectForKey:@"personalDic"];//清除个人资料相关数据
//            [ud removeObjectForKey:@"cnName"];//清除个人资料相关数据
//            [ud synchronize];
//            //        [self removeCashes];
//            
//        }else{
//            //#elif Student
//            NSLog(@"学员端程序");
//            [noti postNotificationName:@"login" object:@"exit"];
//            
//        }
        
        return;
    }
    
    
    return;
}


//计算标题选项卡总长度
- (CGRect)calculateTextLenth:(NSArray *)titleArray andTitleFont:(NSInteger)titleFont{
    //    allLenth = [NSString stringWithFormat:@"%@%@",allLenth,[[self.testDataArray objectAtIndex:j] objectAtIndex:i]];
    NSString *allLenth = [[NSString alloc] init];
    for (int i = 0; i < titleArray.count; i++) {
        allLenth = [NSString stringWithFormat:@"%@%@",allLenth,[titleArray objectAtIndex:i]];
    }
    
    
    UILabel *la =[[UILabel alloc]init];
    la.text = allLenth;
    la.font = [UIFont systemFontOfSize:titleFont];
    float hh = [la sizeThatFits:CGSizeMake(CGFLOAT_MAX, 40)].width;//动态计算高度
    hh += titleArray.count*10+5;
    CGRect rect = [allLenth boundingRectWithSize:CGSizeMake(KWIDTH, 30) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:titleFont]} context:nil];
    for (NSString*title in titleArray) {
        //        rect.size.width += title.length * 4.5+20;
        hh += 20/2;
    }
    NSLog(@"%zd",rect.size.width);
    //    NSInteger lenth = rect.size.width + (k+1)*(14+22)/2+50/2;
    //    CGFloat lineBeyond = ceil(lenth/(KWIDTH-45));
    rect.size.width = hh;
    return rect;
}
//计算标题选项卡单个长度
- (CGSize)calculateOneTextLenth:(NSString *)title andTitleFont:(NSInteger)titleFont{
    
    UILabel *la =[[UILabel alloc]init];
    la.text = title;
    la.font = [UIFont systemFontOfSize:titleFont];
    float hh = [la sizeThatFits:CGSizeMake(CGFLOAT_MAX, 40)].width;//动态计算高度
    CGSize rect = [title boundingRectWithSize:CGSizeMake(KWIDTH, 30) options:NSStringDrawingTruncatesLastVisibleLine |
                   
                   NSStringDrawingUsesLineFragmentOrigin |
                   
                   NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:titleFont]} context:nil].size;
    //    rect.width += title.length * 2-2;
    rect.width = hh;
    //    NSInteger lenth = rect.size.width + (k+1)*(14+22)/2+50/2;
    //    CGFloat lineBeyond = ceil(lenth/(KWIDTH-45));
    return rect;
}


//-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
//    return nil;
//}
//
//-(void)dealloc{
//
//}

@end
